//
//  CompleteViewController.m
//  tcpoctest
//
//  Created by 123456 on 13-8-5.
//  Copyright (c) 2013年 gump. All rights reserved.
//

#import "CompleteViewController.h"
#import "WFLabel_blackShadow.h"
#import "ViewManager.h"
#import "PublicFun.h"
#import "DataControl.h"
#import "SDSegmentedControl.h"
#import "MCSegmentedControl.h"
#import "TencentViewController.h"


#define USERINFO_URL @"https:openmobile.qq.com/get_user_info"
@interface CompleteViewController ()

@end

@implementation CompleteViewController


-(void)initUI{
    self.view.backgroundColor = [UIColor clearColor];
    
    [self createTitle];
    self.mtitle.text = @"完善资料";
    
    //    UIBarButtonItem *backItem = [self createBarButtonItemWithTitle:@"返回" target:self action:@selector(backButtonPressed)];
    UIBarButtonItem *backItem = [self createBarBackButtonItemWithTitle:@"返回" target:self action:@selector(backButtonPressed)];
    self.navItem.leftBarButtonItem = backItem;
    //[backItem release];
    
    UIBarButtonItem *nextItem = [self createBarButtonItemWithTitle:@"下一步" target:self action:@selector(nextButtonPressed)];
    self.navItem.rightBarButtonItem = nextItem;
    //[nextItem release];
    
    UITapGestureRecognizer *singleTouch = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(GestureClick)];
    singleTouch.delegate = self;
    [self.view addGestureRecognizer:singleTouch];
    singleTouch.cancelsTouchesInView = NO;
    
    UIImageView *inputBg = [[UIImageView alloc]initWithFrame:CGRectMake(11.0, 60.0, 298.0, 223.0)];
    inputBg.image = [UIImage imageNamed:@"accountInputBg.png"];
    inputBg.userInteractionEnabled = YES;
    [self.view addSubview:inputBg];
    
    /*
     hidekeyBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, WINDOW_WIDTH, WINDOW_HIGTH)];
     [hidekeyBtn addTarget:self action:@selector(hideKeyClick:) forControlEvents:UIControlEventTouchDown];
     [self.view addSubview:hidekeyBtn];
     */
    
    mailbgv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:I_INPUTBG]];
    mailbgv.frame = CGRectMake(5.5, 10.0, 287.0, 43.0);
    mailbgv.userInteractionEnabled = YES;
    [inputBg addSubview:mailbgv];
    
    maillabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 50, 43)];
    maillabel.textColor = [UIColor colorWithRed:(102.0/255.0) green:(102.0/255.0) blue:(102.0/255.0) alpha:1.0];
    maillabel.font = CENTER_CELL_CONTENT_FONT;
    maillabel.backgroundColor = [UIColor clearColor];
    maillabel.textAlignment = NSTextAlignmentLeft;
    maillabel.text = @"昵称";
    
    mnameField = [[UITextField alloc]initWithFrame:CGRectMake(20, 0, 250, 43)];
    mnameField.backgroundColor = [UIColor clearColor];
    mnameField.leftView = maillabel;
    mnameField.leftViewMode = UITextFieldViewModeAlways;
    mnameField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    mnameField.font = CENTER_CELL_CONTENT_FONT;
    mnameField.textColor = [UIColor blackColor];
    mnameField.placeholder = @"请输入昵称";
    mnameField.returnKeyType = UIReturnKeyDone;
    mnameField.delegate = self;
    [mailbgv addSubview:mnameField];
    //[mnameField release];
    //[maillabel release];
    
    sexbgv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:I_INPUTBG]];
    sexbgv.frame = CGRectMake(5.5, 63.0, 287.0, 43.0);
    sexbgv.userInteractionEnabled = YES;
    [inputBg addSubview:sexbgv];
    //[sexbgv release];
    
    msexlabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 50, 43)];
    msexlabel.textColor = [UIColor colorWithRed:(102.0/255.0) green:(102.0/255.0) blue:(102.0/255.0) alpha:1.0];
    msexlabel.font = CENTER_CELL_CONTENT_FONT;
    msexlabel.backgroundColor = [UIColor clearColor];
    msexlabel.textAlignment = NSTextAlignmentLeft;
    msexlabel.text = @"性别";
    
    msexField = [[UITextField alloc]initWithFrame:CGRectMake(20, 0, 250, 43)];
    msexField.backgroundColor = [UIColor clearColor];
    msexField.leftView = msexlabel;
    msexField.leftViewMode = UITextFieldViewModeAlways;
    msexField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    msexField.font = CENTER_CELL_CONTENT_FONT;
    msexField.text = @"美女";
    msexField.textColor = [UIColor blackColor];
    msexField.enabled = NO;
    [sexbgv addSubview:msexField];
    //[msexlabel release];
    //[msexField release];
    
    NSArray *items = [NSArray arrayWithObjects:
                      [UIImage imageNamed:@"tab_icon_boy.png"],
                      [UIImage imageNamed:@"tab_icon_girl.png"],
					  nil];
	MCSegmentedControl *segmentedControl = [[MCSegmentedControl alloc] initWithItems:items];
	segmentedControl.frame = CGRectMake(140.0f, 8.0f, 120.0f, 30.0f);
	[segmentedControl addTarget:self action:@selector(segmentedControlDidChange:) forControlEvents:UIControlEventValueChanged];
	segmentedControl.selectedSegmentIndex = 1;
	segmentedControl.tintColor = [UIColor colorWithRed:206.0/255.0 green:52.0/255.0 blue:81.0/255.0 alpha:1.0];
	segmentedControl.selectedItemColor   = [UIColor whiteColor];
	segmentedControl.unselectedItemColor = [UIColor colorWithRed:81.0/255.0 green:126.0/255.0 blue:204.0/255.0 alpha:1.0];
    
	[sexbgv addSubview:segmentedControl];
	//[segmentedControl release];
    
    agebgv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:I_INPUTBG]];
    agebgv.frame = CGRectMake(5.5, 116.0, 287.0, 43.0);
    agebgv.userInteractionEnabled = YES;
    [inputBg addSubview:agebgv];
    //[agebgv release];
    
    magelabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 50, 43)];
    magelabel.textColor = [UIColor colorWithRed:(102.0/255.0) green:(102.0/255.0) blue:(102.0/255.0) alpha:1.0];
    magelabel.font = CENTER_CELL_CONTENT_FONT;
    magelabel.backgroundColor = [UIColor clearColor];
    magelabel.textAlignment = NSTextAlignmentLeft;
    magelabel.text = @"年龄:";
    
    mageField = [[UITextField alloc]initWithFrame:CGRectMake(20, 0, 250, 43)];
    mageField.backgroundColor = [UIColor clearColor];
    mageField.leftView = magelabel;
    mageField.leftViewMode = UITextFieldViewModeAlways;
    mageField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    mageField.font = CENTER_CELL_CONTENT_FONT;
    mageField.textColor = [UIColor blackColor];
    mageField.placeholder = @"点击设置年龄";
    [agebgv addSubview:mageField];
    //[magelabel release];
    //[mageField release];
    
    UIButton *selAgeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    selAgeBtn.frame = CGRectMake(0, 0, 250, 43);
    [selAgeBtn addTarget:self action:@selector(ageBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [mageField addSubview:selAgeBtn];
    
    CGRect frame = [[UIScreen mainScreen] bounds];
    frame.origin.y = [[UIScreen mainScreen] bounds].size.height;
    windowPickerView = [[UIView alloc]initWithFrame:frame];
    windowPickerView.backgroundColor = [UIColor colorWithRed:(40/255.0f) green:(40/255.0f) blue:(40/255.0f) alpha:0.6f];
    [self.view addSubview:windowPickerView];
    //[windowPickerView release];
    
    [self initAgePickerView];
    
    citybgv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:I_INPUTBG]];
    citybgv.frame = CGRectMake(5.5, 169.0, 287.0, 43.0);
    citybgv.userInteractionEnabled = YES;
    [inputBg addSubview:citybgv];
    //[citybgv release];
    
    mcitylabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 50, 43)];
    mcitylabel.textColor = [UIColor colorWithRed:(102.0/255.0) green:(102.0/255.0) blue:(102.0/255.0) alpha:1.0];
    mcitylabel.font = CENTER_CELL_CONTENT_FONT;
    mcitylabel.backgroundColor = [UIColor clearColor];
    mcitylabel.textAlignment = NSTextAlignmentLeft;
    mcitylabel.text = @"城市:";
    
    mcityField = [[UITextField alloc]initWithFrame:CGRectMake(20, 0, 250, 43)];
    mcityField.backgroundColor = [UIColor clearColor];
    mcityField.leftView = mcitylabel;
    mcityField.leftViewMode = UITextFieldViewModeAlways;
    mcityField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    mcityField.font = CENTER_CELL_CONTENT_FONT;
    mcityField.textColor = [UIColor blackColor];
    mcityField.placeholder = @"点击选择你所在的城市";
    [citybgv addSubview:mcityField];
    //[mcitylabel release];
    //[mcityField release];
    
    UIButton *selCityBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    selCityBtn.frame = CGRectMake(0, 0, 250, 43);
    [selCityBtn addTarget:self action:@selector(cityBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [mcityField addSubview:selCityBtn];
    
    [self initCityPickerView];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    
    _qqInfoArr = [[NSMutableArray alloc] init];
    TencentViewController * tencentVC = [[TencentViewController alloc] init];
    _qqInfoArr = tencentVC.tokenArray;
    NSLog(@"infoDatas = %@",tencentVC.tokenArray);
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark - connection
-(void)getUserInfo{
    NSString * urlString = [[NSString alloc] initWithFormat:@"%@?%@&openid=%@&oauth_consumer_key=%@&format=json",USERINFO_URL,[_qqInfoArr objectAtIndex:0],[_qqInfoArr objectAtIndex:3],TENCENT_APPID];
    NSURL * url = [NSURL URLWithString:urlString];
    NSURLRequest * request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:15];
    [NSURLConnection connectionWithRequest:request delegate:self];
}

- (void)initAgePickerView
{
    if(!datePicker){
        
        //默认日期格式为yyyy-MM-dd
        dateFormatter= [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
        NSDate *birthdayData = [dateFormatter dateFromString: @"1990-01-01 09:00:00"];
        
        datePicker = [[UIDatePicker alloc]init];
        [datePicker setDate:birthdayData];
        datePicker.frame = CGRectMake(0, 88, 320, 260);
        datePicker.datePickerMode = UIDatePickerModeDate;
        
        datePicker.maximumDate = [dateFormatter dateFromString:@"2000-01-01 09:00:00"];
        datePicker.minimumDate = [dateFormatter dateFromString:@"1900-01-01 09:00:00"];
        
        //构造一个子视图,用于显示日期选择器
        pickerBgView = [[UIView alloc]initWithFrame:CGRectMake(0, [[UIScreen mainScreen] bounds].size.height, 320, 320)];
        pickerBgView.backgroundColor = [UIColor clearColor];
        //为子视图构造工具栏按钮
        UIBarButtonItem* cancel = [[UIBarButtonItem alloc]
                                   initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
                                   target:self action:@selector(dismissDataPicker)];
        UIBarButtonItem* save = [[UIBarButtonItem alloc]
                                 initWithBarButtonSystemItem:UIBarButtonSystemItemDone
                                 target:self action:@selector(saveDataPicker:)];
        UIBarButtonItem	*Space = [[UIBarButtonItem alloc]
                                  initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
                                  target:self action:nil];
        NSArray* buttons = [NSArray arrayWithObjects:cancel,Space,Space,save,nil];
        //为子视图构造工具栏
        UIToolbar *pickerToolbar=[[UIToolbar alloc]initWithFrame:CGRectMake(0, 44, 320, 44)];
        pickerToolbar.barStyle = UIBarStyleBlackTranslucent;
        [pickerToolbar sizeToFit];
        [pickerToolbar setItems:buttons animated:YES]; //把按钮加入工具栏
        [pickerBgView addSubview:pickerToolbar];//把工具栏加入子视图
        //[pickerToolbar release];
        //[cancel release];
        //[save release];
        //[Space release];
        //为子视图构造datePicker
        
        [pickerBgView addSubview:datePicker]; //把datePicker加入子视图
        //[datePicker release];
        //[dateFormatter release];
        
        [self.view addSubview:pickerBgView];
        [self.view bringSubviewToFront:pickerBgView];
        //[pickerBgView release];
    }
}

- (void)showDataPicker
{
    [windowPickerView setFrame:CGRectMake(0, 0, windowPickerView.frame.size.width, windowPickerView.frame.size.height)];
    
    if(pickerBgView != nil){
        [UIView beginAnimations:nil context:UIGraphicsGetCurrentContext()];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        [UIView setAnimationDuration:0.4];
        pickerBgView.center = CGPointMake(pickerBgView.center.x, [[UIScreen mainScreen] bounds].size.height - pickerBgView.frame.size.height/2);
        [UIView commitAnimations];
    }
}

- (void)dismissDataPicker
{
    CGRect frame = [[UIScreen mainScreen] bounds];
    frame.origin.y = [[UIScreen mainScreen] bounds].size.height;
    windowPickerView.frame = frame;
    
    if(pickerBgView != nil){
        [UIView beginAnimations:nil context:UIGraphicsGetCurrentContext()];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        [UIView setAnimationDuration:0.4];
        pickerBgView.center = CGPointMake(pickerBgView.center.x, [[UIScreen mainScreen] bounds].size.height + pickerBgView.center.y);
        [UIView commitAnimations];
    }
}

- (void)saveDataPicker:(id)sender
{
    CGRect frame = [[UIScreen mainScreen] bounds];
    frame.origin.y = [[UIScreen mainScreen] bounds].size.height;
    windowPickerView.frame = frame;
    
    [self dateChange];
    
    if (pickerBgView != nil) {
        [UIView beginAnimations:nil context:UIGraphicsGetCurrentContext()];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        [UIView setAnimationDuration:0.4];
        pickerBgView.center = CGPointMake(pickerBgView.center.x, [[UIScreen mainScreen] bounds].size.height + pickerBgView.center.y);
        [UIView commitAnimations];
    }
}

-(void)dateChange
{
    NSDate* date = datePicker.date;
    
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    
    NSDateComponents *comps = [[NSDateComponents alloc] init];
    NSInteger unitFlags = NSYearCalendarUnit |
    NSMonthCalendarUnit |
    NSDayCalendarUnit |
    NSWeekdayCalendarUnit |
    NSHourCalendarUnit |
    NSMinuteCalendarUnit |
    NSSecondCalendarUnit;
    comps = [calendar components:unitFlags fromDate:date];
    int year=[comps year];
    
    NSDate *datenow = [NSDate date];
    NSCalendar *calendarnow = [NSCalendar currentCalendar];
    NSDateComponents *compsnow;
    compsnow =[calendarnow components:(NSYearCalendarUnit | NSMonthCalendarUnit |NSDayCalendarUnit)
                             fromDate:datenow];
    if ([compsnow month] <= [comps month]) {
        if ([compsnow month] == [comps month])
        {
            if ([compsnow day] < [comps day])
            {
                year = [compsnow year] - year - 1;
            }
            else
            {
                year = [compsnow year] - year;
            }
        }
        else
        {
            year = [compsnow year] - year - 1;
        }
    }
    else
    {
        year = [compsnow year] - year;
    }
    
    mage = year;
    
    mageField.text = [NSString stringWithFormat:@"%d",mage];
}

- (void)initCityPickerView
{
    cityPickerBgView = [[UIView alloc] initWithFrame:CGRectMake(0, [[UIScreen mainScreen] bounds].size.height, 320, 260 + 44)];
    UIBarButtonItem* cancel = [[UIBarButtonItem alloc]
                               initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
                               target:self action:@selector(dismissCityPicker)];
    UIBarButtonItem* save = [[UIBarButtonItem alloc]
                             initWithBarButtonSystemItem:UIBarButtonSystemItemDone
                             target:self action:@selector(saveCityPicker:)];
    UIBarButtonItem	*Space = [[UIBarButtonItem alloc]
                              initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
                              target:self action:nil];
    NSArray* buttons = [NSArray arrayWithObjects:cancel,Space,Space,save,nil];
    //为子视图构造工具栏
    UIToolbar *pickerToolbar=[[UIToolbar alloc]initWithFrame:CGRectMake(0, 24, 320, 44)];
    pickerToolbar.barStyle = UIBarStyleBlackTranslucent;
    [pickerToolbar sizeToFit];
    [pickerToolbar setItems:buttons animated:YES]; //把按钮加入工具栏
    [cityPickerBgView addSubview:pickerToolbar];//把工具栏加入子视图
    //[pickerToolbar release];
    //[cancel release];
    //[save release];
    //[Space release];
    
    cityPicker = [[UIPickerView alloc] init];
    [cityPicker setFrame:CGRectMake(0, 68, cityPicker.frame.size.width, cityPicker.frame.size.height)];
    //    genderPicker.origin = CGPointMake(0, 44);
    cityPicker.showsSelectionIndicator = YES;
    cityPicker.delegate = self;
    cityPicker.dataSource = self;
    [cityPickerBgView addSubview:cityPicker];
    //[cityPicker release];
    
    [self.view addSubview:cityPickerBgView];
    //[cityPickerBgView release];
}

- (void)showCityPicker {
    
    [cityPicker selectRow:rowProvince inComponent:0 animated:NO];
    [cityPicker selectRow:rowCity inComponent:0 animated:NO];
    [windowPickerView setFrame:[[UIScreen mainScreen] bounds]];
    [UIView beginAnimations:nil context:UIGraphicsGetCurrentContext()];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:0.4];
    cityPickerBgView.center = CGPointMake(cityPickerBgView.center.x, [[UIScreen mainScreen] bounds].size.height - cityPickerBgView.frame.size.height/2);
    [UIView commitAnimations];
}

- (void)dismissCityPicker {
    
    CGRect frame = [[UIScreen mainScreen] bounds];
    frame.origin.y = [[UIScreen mainScreen] bounds].size.height;
    windowPickerView.frame = frame;
    
    [UIView beginAnimations:nil context:UIGraphicsGetCurrentContext()];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:0.4];
    cityPickerBgView.center = CGPointMake(cityPickerBgView.center.x, [[UIScreen mainScreen] bounds].size.height + cityPickerBgView.center.y);
    [UIView commitAnimations];
}

- (void)saveCityPicker:(id)sender {
    
    CGRect frame = [[UIScreen mainScreen] bounds];
    frame.origin.y = [[UIScreen mainScreen] bounds].size.height;
    windowPickerView.frame = frame;
    rowProvince = [cityPicker selectedRowInComponent:0];
    rowCity = [cityPicker selectedRowInComponent:1];
    mcityField.text = [NSString stringWithFormat:@"%@ %@",getProvinceFromMapArr(rowProvince),getCityFromMapArr(rowProvince,rowCity)];
    [UIView beginAnimations:nil context:UIGraphicsGetCurrentContext()];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:0.4];
    cityPickerBgView.center = CGPointMake(cityPickerBgView.center.x, [[UIScreen mainScreen] bounds].size.height + cityPickerBgView.center.y);
    [UIView commitAnimations];
}

#pragma mark -private fun-
-(BOOL)InputCheck
{
    BOOL res = NO;
    
    do
    {
        if (mnameField == nil)
        {
            break;
        }
        else if([mnameField.text length] == 0)
        {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示"
                                                            message:@"昵称不能为空,请输入昵称"
                                                           delegate:self
                                                  cancelButtonTitle:@"确认"
                                                  otherButtonTitles:nil];
            [alert show];
            
            break;
        }
        else if([mnameField.text length] > NAME_LIMITE_LENGTH)
        {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示"
                                                            message:@"昵称太长耶"
                                                           delegate:self
                                                  cancelButtonTitle:@"确认"
                                                  otherButtonTitles:nil];
            [alert show];
            
            break;
        }
        else if([mnameField.text rangeOfString:@"碰碰精灵"].length != 0)
        {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示"
                                                            message:@"昵称不可以包含碰碰精灵哦"
                                                           delegate:self
                                                  cancelButtonTitle:@"确认"
                                                  otherButtonTitles:nil];
            [alert show];
            
            break;
        }
        else if([mageField.text length] == 0)
        {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示"
                                                            message:@"年龄不能为空,请输入年龄"
                                                           delegate:self
                                                  cancelButtonTitle:@"确认"
                                                  otherButtonTitles:nil];
            [alert show];
            
            break;
        }
        else if([mcityField.text length] == 0)
        {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示"
                                                            message:@"城市不能为空,请输入城市"
                                                           delegate:self
                                                  cancelButtonTitle:@"确认"
                                                  otherButtonTitles:nil];
            [alert show];
            
            break;
        }
        
        [DataControl shareControl].personDS.uinfo.name = mnameField.text;
        [DataControl shareControl].personDS.uinfo.sex = (char)msex;
        res = YES;
    } while (false);
    
    return res;
}

-(void)hideKeyClick:(id)sender
{
    if ([mnameField isFirstResponder] == YES)
    {
        [mnameField resignFirstResponder];
    }
}


-(void)viewWillHide
{
    
}

-(void)clearUI
{
    mnameField.text = @"";
    mcityField.text = @"";
    mageField.text = @"";
}

- (void)segmentedControlDidChange:(MCSegmentedControl *)sender
{
    if ([sender selectedSegmentIndex] == 1) {
        sender.tintColor = [UIColor colorWithRed:206.0/255.0 green:52.0/255.0 blue:81.0/255.0 alpha:1.0];
        sender.unselectedItemColor = [UIColor colorWithRed:81.0/255.0 green:126.0/255.0 blue:204.0/255.0 alpha:1.0];
        msex = 2;
        msexField.text = @"美女";
    }else{
        sender.tintColor = [UIColor colorWithRed:81.0/255.0 green:126.0/255.0 blue:204.0/255.0 alpha:1.0];
        sender.unselectedItemColor = [UIColor colorWithRed:206.0/255.0 green:52.0/255.0 blue:81.0/255.0 alpha:1.0];
        msex = 1;
        msexField.text = @"帅哥";
    }
}

-(void)GestureClick
{
    if ([mnameField isFirstResponder] == YES)
    {
        [mnameField resignFirstResponder];
    }
}

#pragma mark -button click-
-(void)backButtonPressed
{
    [[ViewManager sharedViewManager] backView:self];
}

-(void)nextButtonPressed
{
    if([self InputCheck])
    {
        [DataControl shareControl].personDS.uinfo.age = (char)mage;
        [DataControl shareControl].personDS.uinfo.province = (char)rowProvince;
        [DataControl shareControl].personDS.uinfo.city = (char)rowCity;
        [[ViewManager sharedViewManager] showMain:true];
    }
}

-(void)ageBtnClick
{
    [self showDataPicker];
}

-(void)cityBtnClick
{
    [self showCityPicker];
}


#pragma mark -textfield delegate-
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return true;
}

#pragma mark- Data Source And Delegate Methods
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 2;
}

-(NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component
{
    if(0==component)
        return [DataControl shareControl].mapArray.count;
    else
    {
        rowProvince=[pickerView selectedRowInComponent:0];
        return [[[[DataControl shareControl].mapArray objectAtIndex:rowProvince] objectForKey:@"Cities"]count];
    }
}
-(CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component
{
    return 150;
}

-(CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component
{
    return 40;
}


-(UIView*)pickerView:(UIPickerView *)pickerView
          viewForRow:(NSInteger)row forComponent:(NSInteger)component
         reusingView:(UIView *)view
{
    CGFloat width=[self pickerView:pickerView widthForComponent:component];
    CGFloat height=[self pickerView:pickerView rowHeightForComponent:component];
    UILabel* label;
    if(nil==view)
    {
        label=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, width, height)];
    }
    else
        label=(UILabel*)view;
    
    if(0==component)
    {
        label.text = getProvinceFromMapArr(row);
        label.backgroundColor = [UIColor clearColor];
        label.font=[UIFont fontWithName:@"Arial" size:20];
        label.textAlignment=NSTextAlignmentCenter;
        
        //label.backgroundColor=[UIColor cyanColor];
    }
    else
    {
        
        rowProvince=[pickerView selectedRowInComponent:0];
        label.backgroundColor = [UIColor clearColor];
        label.text = getCityFromMapArr(rowProvince, row);
        label.font=[UIFont fontWithName:@"Arial" size:20];
        label.textAlignment=NSTextAlignmentCenter;
        
        //label.backgroundColor=[UIColor greenColor];
    }
    
    return label;
}


-(void)pickerView:(UIPickerView *)pickerView
     didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    if(0==component)
    {
        [pickerView reloadComponent:1];
        [pickerView selectRow:0 inComponent:1 animated:NO];
    }
    rowProvince = [pickerView selectedRowInComponent:0];
    rowCity = [pickerView selectedRowInComponent:1];
}


@end
